package com.koo.modules.base.controller;

import com.koo.common.response.R;
import com.koo.common.utils.PageUtils;
import com.koo.modules.base.entity.BaseDictEntity;
import com.koo.modules.base.entity.BaseDictItemEntity;
import com.koo.modules.base.entity.vo.DictVo;
import com.koo.modules.base.service.BaseDictService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author charlin
 * @email 136137465@qq.com
 * @date 2022-06-02 14:50:08
 */
@RestController
@RequestMapping("base/basedict")
public class BaseDictController {
    @Autowired
    private BaseDictService baseDictService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("base:basedict:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = baseDictService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 获取字典数据列表
     * @param params
     * @return
     */
    @RequestMapping("/listDict")
    @RequiresPermissions("goods:goods:list")
    public R listDict(@RequestParam Map<String, Object> params){
        List<BaseDictEntity> list = baseDictService.listDict(params);
        return R.ok().put(list);
    }

    /**
     * 根据dictId获取字典明细数据列表
     * @param dictId
     * @return
     */
    @RequestMapping("/listDictItem/{dictId}")
    @RequiresPermissions("base:basedict:list")
    public R listDictItem(@PathVariable("dictId") Long dictId){
        List<BaseDictItemEntity> list = baseDictService.listDictItem(dictId);
        return R.ok().put(list);
    }


    /**
     * 信息
     */
    @RequestMapping("/getDict")
    @RequiresPermissions("base:basedict:getdict")
    public R getDict(String code){
        List<DictVo> list = baseDictService.getDict(code);
        return R.ok().put(list);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("base:basedict:info")
    public R info(@PathVariable("id") Long id){
		BaseDictEntity baseDict = baseDictService.getById(id);
        return R.ok().put("baseDict", baseDict);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("base:basedict:save")
    public R save(@RequestBody BaseDictEntity baseDict){
		baseDictService.save(baseDict);
        return R.ok();
    }



    /**
     * 更新状态
     */
    @RequestMapping("/updateStatus/{id}/{status}")
    @RequiresPermissions("base:basedict:update")
    public R updateStatus(@PathVariable Long id, @PathVariable Integer status){
        baseDictService.updateStatus(id, status);
        return R.ok();
    }

    /**
     * 更新状态
     */
    @RequestMapping("/updateItemStatus/{id}/{status}")
    @RequiresPermissions("base:basedict:update")
    public R updateItemStatus(@PathVariable Long id, @PathVariable Integer status){
        baseDictService.updateItemStatus(id, status);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("base:basedict:update")
    public R update(@RequestBody BaseDictEntity baseDict){
		baseDictService.updateById(baseDict);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("base:basedict:delete")
    public R delete(@RequestBody Long[] ids){
		baseDictService.batchDelete(ids);
        return R.ok();
    }

}
